package com.example.user_service.service;

import com.example.user_service.dao.UserDelete;
import com.example.user_service.dao.UserInsert;
import com.example.user_service.dao.UserSelect;
import com.example.user_service.dao.UserUpdate;
import com.example.user_service.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author XiaoLiu
 * @date 2021-12-08 16:09
 **/
@Service
public class LserviceImpl implements Lservice {
    @Autowired
    UserSelect userSelect;

    @Autowired
    UserInsert userInsert;

    @Autowired
    UserDelete userDelete;

    @Autowired
    UserUpdate userUpdate;

    @Override
    public List<Administrator> AdministratorSelect(String createdatestr, String enddatestr, String account) {
        return userSelect.AdministratorSelect(createdatestr, enddatestr, account);
    }

    @Override
    public boolean check_Administrator(Administrator administrator) {
        return userSelect.check_Administrator(administrator) == null;
    }

    @Override
    public int create_Administrator(Administrator administrator)
    {
        System.out.println(administrator.getAccount()+"======"+administrator.getRole_name());
        return userInsert.create_Administrator(administrator)+userInsert.create_admi_root(administrator);
    }

    @Override
    public int delete_Administrator(Administrator administrator) {
        return userDelete.delete_Administrator(administrator);
    }

    @Override
    public int update_Administrator(Administrator administrator) {
        return userUpdate.update_Administrator(administrator);
    }

    @Override
    public int update_Administrator_state(Administrator administrator) {
        return userUpdate.update_Administrator_state(administrator);
    }

    @Override
    public User_Member select_member_existing_integral(int userid) {
        return userSelect.select_member_existing_integral(userid);
    }

    @Override
    @Transactional
    public int update_member_existing_integral(int userid, String str, Mingxi mingxi) {
        int i1 = userUpdate.update_member_existing_integral(userid, str);
        int i = userInsert.insert_jf(mingxi);
        if (i1 == 0 || i == 0) {
            throw new RuntimeException("错误");
        }
        return 1;
    }

    @Override
    public List<MyTracks> select_my_tracks(int userid) {
        return userSelect.select_my_tracks(userid);
    }

    @Override
    public int delete_my_tracks(int tracks_id) {
        return userDelete.delete_my_tracks(tracks_id);
    }

    @Override
    public int insert_my_tracks(int user_id, int footprint_id, int goods_type) {
        MyTracks myTracks = userSelect.check_my_tracks(user_id, footprint_id, goods_type);
        if (myTracks == null)
            return userInsert.insert_my_tracks(user_id, footprint_id, goods_type);
        userDelete.delete_my_tracks(Math.toIntExact(myTracks.getTracks_id()));
        return userInsert.insert_my_tracks(user_id, footprint_id, goods_type);
    }

    @Override
    public int delete_my_tracks_date(int userid, String replaceFirst) {
        return userDelete.delete_my_tracks_date(userid, replaceFirst);
    }

    @Override
    public List<CollectGoods> select_collect_goods(int userid) {
        return userSelect.select_collect_goods(userid);
    }

    @Override
    public int delete_collect_goods(int goods_id) {
        return userDelete.delete_collect_goods(goods_id);
    }

    @Override
    public int insert_collect_goods(int user_id, int footprint_id) {
        return userInsert.insert_collect_goods(user_id, footprint_id);
    }

    @Override
    public List<CollectGoods> select_collect_goods1(int user_id, int footprint_id) {
        return userSelect.select_collect_goods1(user_id, footprint_id);
    }

    @Override
    public List<User_welcome> select_user_welcome(int user_id) {
        return userSelect.select_user_welcome(user_id);
    }

    @Override
    public User_Member select_user_member_zeko(int userid) {
        return userSelect.select_user_member_zeko(userid);
    }

    @Override
    public MyTracks check_my_tracks(int user_id, int footprint_id, int goods_type) {
        return userSelect.check_my_tracks(user_id, footprint_id, goods_type);
    }
}
